package algorithm.leetcode.online.q7reverseinteger;
//Reverse digits of an integer.
//
//Example1: x = 123, return 321
//Example2: x = -123, return -321
public class ReverseInteger {
  public static void main(String[] args){
    int a = -123;
    System.out.print(reverseInteger(a));
  }
  private static int reverseInteger(int a){
    int result = 0;
    int sign = a > 0 ? 1 : -1;
    a = Math.abs(a);
    if(a == 0)return a;
    while(a > 0){
      result = result * 10 + a % 10;
      a = a / 10;
    }

    return result*sign;    
  }
}
